package com.btkjgc.utils;

public class VinUtil
{
	static int vinchar[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 0, 7, 0, 9,
			2, 3, 4, 5, 6, 7, 8, 9 };
	static int factor[] = { 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 };
	
	public static String getChecksum(String vin)
	{
		int checksum = 0;
		for (int i = 0; i < vin.length(); i++)
		{
			if (i != 8)
			{
				char c = vin.charAt(i);
				int v = 0;
				if (c >= '0' && c <= '9')
				{
					v = c - '0';
				}
				else
				{
					v = vinchar[c - 'A'];
				}
				v = v * factor[i];
				checksum += v;
			}
		}
		return (checksum % 11) +"";
	}
}
